package com.ruoyi.common.utils.net;

import java.util.List;
import java.util.stream.Collectors;

public class HexUtil {

    /**
     * hex字符串转10进制
     * @param hexStr
     * @return
     */
    public static int hexStrToInt(String hexStr){
        return Integer.parseInt(hexStr,16);
    }

    /**
     * hexList 分割拼接为字符串
     * @param hexList
     * @param startPos
     * @param endPos
     * @return
     */
    public static String hexListToStr(List<String> hexList,int startPos,int endPos){
        List<String> rList = hexList.subList(startPos, endPos);
        return rList.stream().collect(Collectors.joining(""));
    }


    /**
     * hexList拼接为字符串
     */
    public static String hexListToStr(List<String> hexLists){
        return hexLists.stream().collect(Collectors.joining(""));
    }


    /**
     * 数字转hex字符串(1位)
     */
    public static String intToHexStr1(int num){
        String hexStr = String.format("%02x", num);
        //System.out.println("int => hex  "+hexStr);
        return hexStr;
    }


    /**
     * 数字转hex字符串(1位)
     */
    public static String intToHexStr2(int num){
        String hexStr = String.format("%04x", num);
        //System.out.println("int => hex  "+hexStr);
        return hexStr;
    }


    /**
     * list字符串转 hexstr
     */

    public static String listToStrBySymbol(List<String> list,String symbol){
        return list.stream().collect(Collectors.joining(symbol));
    }
}
